import java.util.concurrent.Semaphore;

/**
 * This class implements a concurrent grading queue that may simultaneously process grading jobs.
 */
public class ConcurrentGradingQueue {
	Semaphore semJobs;
	
    /**
     * The constructor should initialize as an instance variable a Semaphore with maxConcurrentJobs number of slots.
     */
    public ConcurrentGradingQueue (int maxConcurrentJobs) {
    	semJobs = new Semaphore(maxConcurrentJobs);
    }

    /**
     * This method should instantiate a ConcurrentGradingJob with the Semaphore stored in this object. It should then
     * create a new Thread with the ConcurrentGradingJob (which is a Runnable) and start the thread with the start()
     * method.
     */
    public void addToQueue (Submission submission) {
    	ConcurrentGradingJob gradeJob = new ConcurrentGradingJob(submission, semJobs);
    	Thread worker = new Thread(gradeJob);
    	worker.start();
    }

}
